package com.loopy.fruns.dao.impl;

import com.loopy.fruns.dao.BasicDAO;
import com.loopy.fruns.dao.MemberDAO;
import com.loopy.fruns.entity.Member;

public class MemberDAOImpl extends BasicDAO<Member> implements MemberDAO {
    /**
     * 根据用户名返回对应的Member
     * @param username
     * @return
     */
    @Override
    public Member queryMemberByUserName(String username) {
        String sql="select * from member where username=?";
        Member member = QuerySingle(sql, Member.class, username);
        return member;
    }

    /**
     * 保存Member对象到数据库
     * @param member
     * @return-1表示失败 其他表示受影响的行数
     */
    @Override
    public int saveMember(Member member) {
        String sql="insert into `member`(`username`,`password`,`email`) values(?,md5(?),?)";
        int update = update(sql, member.getUsername(), member.getPassword(), member.getEmail());
        return update;
    }

    @Override
    public Member queryMemberByUserNameAndPassword(String username,String password) {
        String sql="select * from member where username=? and password=md5(?)";
        Member member = QuerySingle(sql, Member.class, username,password);
        return member;
    }
}
